package com.zoe.app.dynamic;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zoe.Zhang
 * @date 2023/02/24
 * @description
 */
@Slf4j
public class DynamicDataSourceContextHolder {
    private static final ThreadLocal<String> THREAD_CONTEXT = new ThreadLocal<>();

    public static void setDataSource(String dataSource) {
        log.info("数据源切换 --> {}", dataSource);
        THREAD_CONTEXT.set(dataSource);
    }

    public static String getDataSource() {
        return THREAD_CONTEXT.get();
    }

    public static void clearDataSource() {
        log.info("数据源清除");
        THREAD_CONTEXT.remove();
    }
}
